package com.song.tools.songtest.service;

import com.song.tools.mvc.service.AggregationService;
import com.song.tools.mvc.validator.ValidationResult;
import com.song.tools.mvc.validator.ValidatorChain;
import com.song.tools.songtest.beans.poi.DictionaryDetailImportDto;
import com.song.tools.songtest.beans.request.DictionaryDetailQueryRequest;
import com.song.tools.songtest.beans.request.DictionaryDetailSaveRequest;
import com.song.tools.songtest.beans.request.DictionaryDetailUpdateRequest;
import com.song.tools.songtest.beans.response.DictionaryDetailDeleteResponse;
import com.song.tools.songtest.beans.response.DictionaryDetailQueryResponse;
import com.song.tools.songtest.beans.response.DictionaryDetailSaveResponse;
import com.song.tools.songtest.beans.response.DictionaryDetailUpdateResponse;
import jakarta.servlet.http.HttpServletResponse;

import java.util.List;

/**
 * <p>
 * 字典明细表 服务类
 * </p>
 *
 * @author song tools
 * @since 2024-07-09
 */
public interface DictionaryDetailService extends AggregationService<Long, DictionaryDetailQueryRequest, DictionaryDetailQueryResponse,
        DictionaryDetailSaveRequest, DictionaryDetailSaveResponse, DictionaryDetailUpdateRequest, DictionaryDetailUpdateResponse, DictionaryDetailDeleteResponse, HttpServletResponse> {

    @Override
    default ValidationResult validateOnSave(DictionaryDetailSaveRequest dictionaryDetailSaveRequest) {
        ValidatorChain validatorChain = new ValidatorChain();

        // save时校验参数
        return validatorChain.validate();
    }


    @Override
    default ValidationResult validateOnUpdate(DictionaryDetailUpdateRequest dictionaryDetailUpdateRequest) {
        ValidatorChain validatorChain = new ValidatorChain();

        // update时校验参数
        return validatorChain.validate();
    }


    /**
     * 导入前的数据校验
     *
     * @param importDtos 导入dto
     */
    default ValidationResult validateOnImport(List<DictionaryDetailImportDto> importDtos) {
        for (DictionaryDetailImportDto importDto : importDtos) {
            ValidatorChain validatorChain = new ValidatorChain();

            // import时校验参数
            ValidationResult validationResult = validatorChain.validate();
            if (!validationResult.isValid()) {
                return validationResult;
            }
        }
        return ValidationResult.success();
    }
}

